const TokenKey = 'Admin-Token'
const Username = 'Username'
const LastUrl = 'LastUrl'
const sysCode = '_zj'
const remember = 'remember'

export function getLastUrl(username) {
  if (username) {
    return sessionStorage.getItem(LastUrl + sysCode + username)
  } else {
    return sessionStorage.getItem(LastUrl + sysCode + getUsername())
  }
}

export function setRemember() {
  localStorage.setItem(remember + sysCode, '1')
}

export function getRemember() {
  const r = localStorage.getItem(remember + sysCode)
  return !!r
}

export function delRemember() {
  localStorage.removeItem(remember + sysCode)
}

export function setLastUrl(url, username) {
  if (username) {
    sessionStorage.setItem(LastUrl + sysCode + username, url)
  } else {
     sessionStorage.setItem(LastUrl + sysCode + getUsername(), url)
  }
}

export function getToken() {
  return sessionStorage.getItem(TokenKey)
}

export function setToken(token) {
  return sessionStorage.setItem(TokenKey, token)
}

export function removeToken() {
  sessionStorage.removeItem(TokenKey)
}

export function getUsername() {
  return localStorage.getItem(Username + sysCode)
}

export function setUsername(username) {
  return localStorage.setItem(Username + sysCode, username)
}

